package com.hdhere.domain.media;

import com.hdhere.domain.common.BaseEntity;
import com.hdhere.domain.common.enums.RowState;
import com.hdhere.domain.common.util.IdWorker;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Base64;
import java.util.Date;

@ApiModel(value = "VideoPost", description = "视频发布")
@Entity
@Table(name = "videoPost", schema = "media")
public class VideoPost extends BaseEntity {

    private static final long serialVersionUID = 1L;

    @Id
    private Long Id;

    @Column(columnDefinition="binary(20)", length = 20)
    private byte[] videoId;

    private Long cateId;

    @ApiModelProperty(value = "目录路径")
    @Column(length = 80)
    private String catePath;

    @Column(length = 80, columnDefinition="nvarchar(80)")
    private String cateName;

    @Column(length = 120, columnDefinition="nvarchar(120)")
    private String title;

    @Column(length = 1500, columnDefinition="nvarchar(1500)")
    private String body;

    @ApiModelProperty(value = "缩略图地址，分隔")
    private String thumbnail;

    @ApiModelProperty(value = "下载地址")
    private String downloadUrl;

    @ApiModelProperty(value = "发布状态")
    @Column(columnDefinition="tinyint")
    private short state;

    @ApiModelProperty(value = "发布时间")
    @Column(columnDefinition="datetime")
    private Date postDate;


    public void resetData(){
        if(getId()==null) {
            setId(IdWorker.nextId());
            //默认有效
            setState(RowState.Effective.getId());
            setPostDate(new Date());

        }

    }

    public Long getId() {
        return Id;
    }

    public void setId(Long id) {
        Id = id;
    }

    public byte[] getVideoId() {
        return videoId;
    }

    public void setVideoId(String videoId) {
        this.videoId = Base64.getDecoder().decode(videoId);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    public Long getCateId() {
        return cateId;
    }

    public void setCateId(Long cateId) {
        this.cateId = cateId;
    }

    public String getCatePath() {
        return catePath;
    }

    public void setCatePath(String catePath) {
        this.catePath = catePath;
    }

    public String getCateName() {
        return cateName;
    }

    public void setCateName(String cateName) {
        this.cateName = cateName;
    }

    public String getDownloadUrl() {
        return downloadUrl;
    }

    public void setDownloadUrl(String downloadUrl) {
        this.downloadUrl = downloadUrl;
    }

    public Date getPostDate() {
        return postDate;
    }

    public void setPostDate(Date postDate) {
        this.postDate = postDate;
    }

    public short getState() {
        return state;
    }

    public void setState(short state) {
        this.state = state;
    }

    public String getThumbnail() {
        return thumbnail;
    }

    public void setThumbnail(String thumbnail) {
        this.thumbnail = thumbnail;
    }
}
